<template>
	<view class="page">
		<view class="heater pt-5  border-bottom border-light-secondary">
			<view class="title font-lg font-weight text-center line-clamp2 position-relative">
				<text class="line-h-sm">{{ newInfo.title }}</text>

				<view class="position-absolute top-0" style="right:20rpx;" @tap="collectionChange"><u-icon name="star-fill" :color="star ? '#ff962f' : '#ccc'" size="42"></u-icon></view>
			</view>

			<view class="text-right mt-2 pb-3 font text-light-muted">{{ newInfo.time | dateFormat('data') }}</view>
		</view>

		<image :src="newInfo.filePath || errLoadImg" mode="" class="mt-2 rounded" style="width: 100%;height: 354rpx;" mode="aspectFill"></image>

		<view class="info textIndent2 py-2">
			<text class="fontmd">{{ newInfo.infoContext }}</text>
		</view>

		<view class="pl-5 mt-3">(编辑：{{ newInfo.author }})</view>
		<view class="pl-5 pb-3">(来源：{{ newInfo.source }} {{ newInfo.platform }})</view>
		<line />
	</view>
</template>

<script>
import { CurrentAffairsById } from '@/api/partyBuild/index.js';
import { NewsId } from '@/api/home/index.js';
import { dateFormat } from '@/filter/index.js';
export default {
	filters: {
		dateFormat
	},
	data() {
		return {
			star: false,
			id: 0,
			newInfo: {},
			errLoadImg: '/static/images/errLoad.jpeg'
		};
	},
	onLoad(op) {
		const ops = JSON.parse(op.data);
		this.id = ops.id;
		if (ops.key === 'sszz') {
			this.getAffairsInfo(ops.id);
		} else if (ops.key === 'yq') {
			this.getNewInfoById(ops.id);
		}
	},
	methods: {
		async getNewInfoById(id) {
			// 园区动态

			const res = await NewsId(id);
			if (res.flag) {
				this.newInfo = res.result;
				this.newInfo.title = res.result.activityTitle;
				this.newInfo.time = res.result.activityTime;
				this.newInfo.infoContext = res.result.activityInfo;
				this.newInfo.author = res.result.activityAuthor || '暂无';
				this.newInfo.source = res.result.activitySource || '转载';
				this.newInfo.platform = res.result.activityPlatform || '微信公众号';
				
				
				uni.setNavigationBarTitle({
					title: res.result.activityTitle
				});
			}
		},
		async getAffairsInfo(id) {
			// 时事政治详情

			const res = await CurrentAffairsById(id);
			if (res.flag) {
				this.newInfo = res.result;
				this.newInfo.title = res.result.policyTitle;
				this.newInfo.time = res.result.policyTime;
				this.newInfo.infoContext = res.result.policyInfo;
				this.newInfo.author = res.result.policyAuthor || '';
				this.newInfo.source = res.result.policySource || '';
				this.newInfo.platform = res.result.policyPlatform || '';
				uni.setNavigationBarTitle({
					title: res.result.policyTitle
				});
			}
		},
		collectionChange() {
			this.star = !this.star;
			uni.showToast({
				title: this.star ? '已收藏' : '取消收藏',
				icon: 'success'
			});
		}
	}
};
</script>

<style scoped>
.page {
	background-color: #fff;
	height: 100%;
	padding: 0 20rpx;
}

.title {
	padding-right: 80rpx;
}
</style>
